<html>
<head>
	<meta charset="UTF-8">
	<meta content="IE=edge" http-equiv="X-UA-Compatible">
	<meta content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width" name="viewport">
	<title>2359：商船运输</title>
	<!-- css -->
	<link href="../css/base.min.css" rel="stylesheet">
	<link href="../css/project.min.css" rel="stylesheet">
	
	<!-- favicon -->
	<!-- ... -->
</head>
<body class="page-brand">
	<header class="header header-transparent header-waterfall ui-header">
		<ul class="nav nav-list pull-left">
			<li>
				<a data-toggle="menu" href="#menu">
					<span class="icon icon-lg">menu</span>
				</a>
			</li>
		</ul>
		<a class="header-logo header-affix-hide margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">商船运输</a>
		<span class="header-logo header-affix margin-left-no margin-right-no" data-offset-top="213" data-spy="affix">商船运输</span>
	</header>
	<nav aria-hidden="true" class="menu" id="menu" tabindex="-1">
		<div class="menu-scroll">
			<div class="menu-content">
				<a class="menu-logo" href="../index.html">BZOJ离线题库</a>
				<ul class="nav">
					<li>
						<a class="waves-attach" data-toggle="collapse" href="#problems">题目</a>
						<ul class="menu-collapse collapse in" id="problems">
							<li>
								<a class="waves-attach" href="../index.html">主页</a>
							</li>
							<li>
								<a class="waves-attach" href="../list.html">题目列表</a>
							</li>
						</ul>
					</li>
					<li>
						<a class="collapsed waves-attach" data-toggle="collapse" href="#about">关于</a>
						<ul class="menu-collapse collapse" id="about">
							<li>
								<a class="waves-attach" href="../about.html">关于此项目</a>
							</li>
						</ul>
					</li>
					
				</ul>
			</div>
		</div>
	</nav>
	<main class="content">
		<div class="content-header ui-content-header">
			<div class="container">
				<h1 class="content-heading">
                商船运输                </h1>
                <p>时间限制：3s&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;  空间限制：128MB</p>			</div>
		</div>
		<div class="container">
			<section class="content-inner margin-top-no">
				<div class="row">
					<div class="col-lg-13 col-md-13">
						<div class="card margin-bottom-no">
							<div class="card-main">
								<div class="card-inner">
									
                                <h3>题目描述</h3><p><div align="center"></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">开辟新航路以后，欧洲的海上贸易日益繁荣，许多商人带领着他们的船队，在世界各地来往穿梭。这其中有位很有头脑的</span><span style="font-size: 12pt">XX</span><span style="font-size: 12pt">船长，他十分重视收集各港口的供需情报，并以此确定他的下一步计划，通过减少运输的时间来获取更多的利益。他的情报包括以下的内容：</span></div>
<div style="text-justify: inter-ideograph; text-indent: 1cm; line-height: 20pt; text-align: justify"><span style="font-size: 12pt">1．<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">一幅完整的航海图。这其中包含了陆地、海洋以及各港口的位置。船只每次只能沿上下左右四个方向移动一格</span><span style="font-size: 12pt">(</span><span style="font-size: 12pt">不可移到陆地上和地图外</span><span style="font-size: 12pt">,</span><span style="font-size: 12pt">可移进港口</span><span style="font-size: 12pt">)</span><span style="font-size: 12pt">，且每次移动都需航行一天。</span></div>
<div style="text-justify: inter-ideograph; text-indent: 1cm; line-height: 20pt; text-align: justify"><span style="font-size: 12pt">2．<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">各港口可供应的货物。当然，每种货物不可能到处都买的到，否则就用不着船队了。因此，规定每种货物最多只有</span><span style="font-size: 12pt">20</span><span style="font-size: 12pt">个的港口供应。</span></div>
<div style="text-justify: inter-ideograph; text-indent: 1cm; line-height: 20pt; text-align: justify"><span style="font-size: 12pt">3．<span style="font: 7pt 'Times New Roman'">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span></span><span style="font-size: 12pt">各港口需要的货物。与情报</span><span style="font-size: 12pt">2</span><span style="font-size: 12pt">不同的是，各港所需的货物是变化的，即</span><span style="font-size: 12pt">XX</span><span style="font-size: 12pt">船长是逐渐得到新情报的。同时，每当他得到一个新的货物需求</span><span style="font-size: 12pt">(i,j)(</span><span style="font-size: 12pt">表示港口</span><span style="font-size: 12pt">j</span><span style="font-size: 12pt">需要货物</span><span style="font-size: 12pt">i)</span><span style="font-size: 12pt">，他必须马上作出决策：选择几号船完成此任务。因为要计算出怎样最优是比较困难的，所以船长采取了这样一个近似的方法：找出&ldquo;完成新任务所需时间&rdquo;最少的船，将其用来完成新任务，若有多艘这样的船，则从中选择编号最小的。</span><span style="font-size: 12pt">(</span><span style="font-size: 12pt">&ldquo;完成新任务所需时间&rdquo;包含两个过程：航行到一个供应货物</span><span style="font-size: 12pt">i</span><span style="font-size: 12pt">的港口并上货和将货物</span><span style="font-size: 12pt">i</span><span style="font-size: 12pt">运到港口</span><span style="font-size: 12pt">j</span><span style="font-size: 12pt">并卸货，其中上货和卸货的时间忽略不计。因为上货港口的选择不同，所需的时间也会不同，所以，必须对上货的港口进行选择，使该船的&ldquo;完成新任务所需时间&rdquo;尽量短</span><span style="font-size: 12pt">)</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">XX</span><span style="font-size: 12pt">船长想要知道的是：他的所有船只共需多少时间来完成这些任务，即所有船只完成各自任务的时间和。</span></div>
<div style="line-height: 20pt"><b>&nbsp;</b></div></p><hr/><h3>输入格式</h3><p><div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12pt">第一行是是六个数</span><span style="font-size: 12pt">N</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">M</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">port_num</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">good_num</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">ship_num</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">start</span><span style="font-size: 12pt">，表示航海图的长、宽，以及港口总数、货物种类和船长拥有的船只数、所有船的初始位置</span><span style="font-size: 12pt">(</span><span style="font-size: 12pt">停泊的港口编号</span><span style="font-size: 12pt">)</span><span style="font-size: 12pt">。</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12pt">以下</span><span style="font-size: 12pt">N+1</span><span style="font-size: 12pt">行是一个</span><span style="font-size: 12pt">N&times;M</span><span style="font-size: 12pt">的矩阵，在矩阵中</span><span style="font-size: 12pt">0</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">1</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">2</span><span style="font-size: 12pt">分别对应海洋、港口和陆地。港口的编号对应由上至下，由左至右</span><span style="font-size: 12pt">(</span><span style="font-size: 12pt">由上至下优先</span><span style="font-size: 12pt">)</span><span style="font-size: 12pt">的读入顺序，第一个读入的港口编号为</span><span style="font-size: 12pt">1</span><span style="font-size: 12pt">，第二个读入的港口编号为</span><span style="font-size: 12pt">2</span><span style="font-size: 12pt">&hellip;&hellip;</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12pt">第</span><span style="font-size: 12pt">N+2</span><span style="font-size: 12pt">行到第</span><span style="font-size: 12pt">N+port_num+1</span><span style="font-size: 12pt">行按编号顺序给出了各港口供应的货物，其格式为：</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; N1 p11 &nbsp;p12 &nbsp;&hellip; p1N1</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; N2 p21 &nbsp;p22 &nbsp;&hellip; p2N2</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &hellip; &hellip;&nbsp;&hellip;&nbsp;&hellip; &hellip;</span></div>
<div style="text-indent: 21.25pt; line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp; Ni pi1 &nbsp;pi2 &nbsp;&hellip; piNi</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &hellip; &hellip;&nbsp;&hellip;&nbsp;&hellip; &hellip;</span></div>
<div style="text-indent: 21.25pt; line-height: 20pt"><span style="font-size: 12pt">&nbsp;Nport_num&nbsp;pport_num1 pport_num2 &hellip; pport_numNport_num</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Ni</span><span style="font-size: 12pt">是港口</span><span style="font-size: 12pt">i</span><span style="font-size: 12pt">供应的货物总数，</span><span style="font-size: 12pt">pij</span><span style="font-size: 12pt">是港口</span><span style="font-size: 12pt">i</span><span style="font-size: 12pt">供应的第</span><span style="font-size: 12pt">j</span><span style="font-size: 12pt">种货物编号。</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;&nbsp;&nbsp;&nbsp; </span><span style="font-size: 12pt">第</span><span style="font-size: 12pt">N+port_num+2</span><span style="font-size: 12pt">行是一个数</span><span style="font-size: 12pt">Total</span><span style="font-size: 12pt">，表示情报</span><span style="font-size: 12pt">3</span><span style="font-size: 12pt">中获得的任务总数，以下</span><span style="font-size: 12pt">Total</span><span style="font-size: 12pt">行按情报获得的时间给出了</span><span style="font-size: 12pt">Total</span><span style="font-size: 12pt">个任务，每个任务占一行，包含两个数</span><span style="font-size: 12pt">i</span><span style="font-size: 12pt">、</span><span style="font-size: 12pt">j</span><span style="font-size: 12pt">，表示港口</span><span style="font-size: 12pt">j</span><span style="font-size: 12pt">需要货物</span><span style="font-size: 12pt">i</span><span style="font-size: 12pt">。</span></div>
<div style="line-height: 20pt"><span style="font-size: 12pt">文件一行中相临两数用一个或多个空格隔开。</span></div>
<div style="line-height: 15pt"><b>&nbsp;</b></div></p><hr/><h3>输出格式</h3><p><div style="line-height: 20pt"><span style="font-size: 12pt">&nbsp;</span><span style="font-size: 12pt">仅有一个数</span><span style="font-size: 12pt">T</span><span style="font-size: 12pt">，是你的程序得出的所有船只完成各自任务的时间和。</span></div></p><hr/><h3>样例输入</h3><pre>5 5 3 4 2 1
0 1 0 0 0
2 2 2 0 0
0 1 2 0 2
0 2 2 0 1
0 0 0 0 0
1 3
3 1 2 4
1 4
4
1 3
2 3
3 2
4 1
</pre><hr/><h3>样例输出</h3><pre>54
</pre><hr/><h3>提示</h3><p><p>数据范围<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1&le;N、M&le;100，1&le;port_num&le;100,1&le;good_num</p></p><hr/><h3>题目来源</h3><p>没有写明来源</p>
								</div>
							</div>
						</div>
					</div>
				</div>
				
				
			</section>
		</div>
	</main>

	<div class="fbtn-container">
		<div class="fbtn-inner">
			<a class="fbtn fbtn-lg fbtn-brand-accent waves-attach waves-circle waves-light waves-effect" data-toggle="dropdown" aria-expanded="true"><span class="fbtn-text fbtn-text-left">Menu</span><span class="fbtn-ori icon">apps</span><span class="fbtn-sub icon">close</span></a>
			<div class="fbtn-dropup">
				<a class="fbtn fbtn-brand waves-attach waves-circle waves-light waves-effect" href="../list.html" target="_self"><span class="fbtn-text fbtn-text-left">题目列表</span><span class="icon">menu</span></a>
				<a class="fbtn fbtn-green waves-attach waves-circle waves-effect" href="../index.html" target="_self"><span class="fbtn-text fbtn-text-left">返回主页</span><span class="icon">home</span></a>
				<a class="fbtn waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/submitpage.php?id=2359" target="_blank"><span class="fbtn-text fbtn-text-left">提交代码</span><span class="icon">send</span></a>
				<a class="fbtn fbtn-orange waves-attach waves-circle waves-effect" href="http://www.lydsy.com/JudgeOnline/wttl/wttl.php?pid=2359" target="_blank"><span class="fbtn-text fbtn-text-left">试题讨论</span><span class="icon">chat</span></a>
				
			</div>
		</div>
	</div>

	<!-- js -->
	<script src="../js/jquery.min.js"></script>
	<script src="../js/base.min.js"></script>
	<script src="../js/project.min.js"></script>
</body>
</html>